/**
 * Created by Administrator on 2018/6/1 0001.
 */
$("#form").validate({
    rules: {
        username: {
            required: true,
        },
        password: {
            required: true,
        }
    },
    messages: {
        username: {
            required: "请输入用户名称",
        },
        password: {
            required: "请输入密码",
        }
    },
    submitHandler: function (form) {
        let data = $(form).serializeArray();
        let formData = {}
        $.each(data, function (index, data) {
            formData[data.name] = data.value; //通过变量，将属性值，属性一起放到对象中
        })
        $.ajax({
            url: "/api/login",
            type: 'post',
            data: JSON.stringify(formData),
            // beforeSend: function (XMLHttpRequest) {
            //     XMLHttpRequest.setRequestHeader("authorization", "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxOD.....");
            // },
            success: function (res) {
                if(res.code){
                    location.href='/index'
                }else{
                    console.log()
                }
                console.log(res)
            }
        })
    }
})